package com.ayf.payment.game.api.config;

import com.swwx.charm.zookeeper.lock.DistributedLock;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;

/**
 * Created by Ful on 2015/7/30.
 */
@Configuration
public class ApplicationConfig {
    @Value("${GAME_AYFPAY_ZOOKEEPER_HOST}")
    public String zookeeperHost;

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

    @Bean(destroyMethod = "destroy")
    public DistributedLock distributedLock() {
        return new DistributedLock(zookeeperHost, "com.ayf.payment.game.api");

    }

    @Bean
    public CuratorFramework curatorFramework() {
        return CuratorFrameworkFactory.newClient(zookeeperHost, new RetryNTimes(5, 1000));
    }

}
